<template>
    <div>
      <Modal width="300" footer-hide v-model="changeStatusShow" title="状态变更" >
        <div class="report-content">
          <Select v-model="changeParams.customerStatus" placeholder="报备状态">
            <Option v-for="item in customerStatusList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
          <textarea v-model="changeParams.remark" ></textarea>
          <div>
            <Button type="success" @click="changeReportStatus">强制变更</Button>
          </div>
          <div style="color: red;">V10缺少强制同步接口，状态变更后只针对渠道王有效.V10相关后续逻辑待添加 </div>
        </div>
      </Modal>
    </div>
</template>

<script>
import { formatTime } from '@/utils'
import Api from '@/api'

const report = Api.report
export default {
  name: 'changeStatusModal',
  data() {
    return {
      changeStatusShow: false,
      changeReportDetail: {},
      customerStatusList: [
        {
          label: '无效',
          value: '-1'
        },
        {
          label: '待审核',
          value: '0'
        },
        {
          label: '未到访',
          value: '10'
        },
        {
          label: '已到访',
          value: '6'
        }
      ],
      changeParams: {
        customerPremisesId: '',
        customerStatus: '',
        remark: ''
      }
    }
  },
  methods: {
    initData(params) {
      this.changeReportDetail = params;
      this.changeParams.customerPremisesId = params.id;
      this.changeStatusShow = true;
    },
    cleanParams() {
      this.changeParams = {};
    },
    changeReportStatus() {
      const _self = this;
      if (!_self.changeParams.customerPremisesId) {
        this.$Message.success('缺少报备Id,请刷新重新打开！');
        return;
      }
      if (!_self.changeParams.customerStatus) {
        this.$Message.success('未选中变更状态, 请选择！！！');
        return;
      }
      const oldCustomerStatus = _self.changeReportDetail.customerStatus;
      let newCustomerStatus = _self.changeParams.customerStatus;
      if (newCustomerStatus === '-1') {
        newCustomerStatus = '无效';
      } else if (newCustomerStatus === '0') {
        newCustomerStatus = '待审核';
      } else if (newCustomerStatus === '10') {
        newCustomerStatus = '未到访';
      } else if (newCustomerStatus === '6') {
        newCustomerStatus = '已到访';
      }
      this.$Modal.confirm({
        title: '报备状态变更',
        content: 'V10缺少强制同步接口，状态变更后只针对渠道王有效\n 状态由【' + oldCustomerStatus + '】变更为【' + newCustomerStatus + '】, 是否确认操作?',
        onOk: () => {
          _self.changeReportConfirm(_self.changeParams);
        }
      })
    },
    async changeReportConfirm(params) {
      const { responseCode, responseMessage, responseType } = await this.$request(report.changeStatus, params)
      this.$Message.success(responseMessage);
      this.changeStatusShow = false;
    },
  }
}
</script>

<style scoped>
  .report-detail{margin: 10px 0;}
  .report-follow{margin: 10px 0;}
  .report-content{height: 200px;overflow-y:scroll}
</style>
